//
//  PlayTableViewCell.m
//  TravelEveryDay
//
//  Created by 路洪宇 on 15/10/15.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "PlayTableViewCell.h"

@implementation PlayTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    }
    return self;
}

- (void)createView
{
    
    //白色背景
    _bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 10,SCREEN_WIDTH-20,320)];
    [_bgView setBackgroundColor:[UIColor whiteColor]];
    _bgView.layer.cornerRadius = 5;
    _bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:_bgView];
    
    //内容站位图
    UIImageView *contentView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, (SCREEN_WIDTH-20)/2+10)];

    contentView.image = [UIImage imageNamed:@"placeHolder.jpg"];
    [_bgView addSubview:contentView];
    //内容图像
    _title_pageImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, (SCREEN_WIDTH-20)/2+20)];
    [_bgView addSubview:_title_pageImageView];

   
    //用户头像站位图
    UIImageView *userView = [[UIImageView alloc]initWithFrame:CGRectMake(_title_pageImageView.frame.size.width-100, _title_pageImageView.frame.size.height-35, 70, 70)];
    userView.image = [UIImage imageNamed:@"playAvatar_placeholder.png"];
    [_bgView addSubview:userView];
    //用户头像
    _avatar_lImageView = [[UIImageView alloc]initWithFrame:CGRectMake(_title_pageImageView.frame.size.width-100, _title_pageImageView.frame.size.height-35, 70, 70)];
    _avatar_lImageView.layer.cornerRadius = 35.;
    _avatar_lImageView.layer.masksToBounds = YES;
    _avatar_lImageView.layer.borderWidth = 4;
 
    _avatar_lImageView.layer.borderColor = [[UIColor whiteColor]CGColor];
    [_bgView addSubview:_avatar_lImageView];
    
    //标题
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5+_title_pageImageView.frame.size.height, 200, 50)];
    _titleLabel.numberOfLines = 0.;
    [_titleLabel setFont:[UIFont boldSystemFontOfSize:18.]];
    [_bgView addSubview:_titleLabel];
    //时间 //地址 //喜欢数
    _addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.frame.origin.y + _titleLabel.frame.size.height+5, SCREEN_WIDTH-40, 20)];
    _addressLabel.font = [UIFont systemFontOfSize:14];
    _addressLabel.textColor = [UIColor grayColor];
    _addressLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    [_bgView addSubview:_addressLabel];
 
    //价格
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_avatar_lImageView.frame.origin.x, _avatar_lImageView.frame.origin.y+95, 70, 70)];
    [_priceLabel setTextAlignment:NSTextAlignmentCenter];
    _priceLabel.textColor = [UIColor colorWithRed:1 green:0.43 blue:0.01 alpha:1];
    _priceLabel.font = [UIFont systemFontOfSize:23.];
    [_bgView addSubview:_priceLabel];
    
    _tab_listLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _avatar_lImageView.frame.origin.y+120,200, 30)];
    _tab_listLabel.font = [UIFont systemFontOfSize:14.];
    _tab_listLabel.textColor = [UIColor grayColor];
     [_bgView addSubview:_tab_listLabel];
}

- (void)getInfo:(PlayModel *)model
{
    [self.title_pageImageView sd_setImageWithURL:[NSURL URLWithString:model.title_page]];
    [self.titleLabel setText:model.title];
    [self.avatar_lImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar_l]];

    [self.addressLabel setText:[NSString stringWithFormat:@"%@ · %@ · %@人喜欢",model.date_str,model.address,model.like_count]];
    
    
    NSMutableAttributedString *mutableString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%@", model.price]];
    [mutableString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:13.0] range:NSMakeRange(0, 1)];
    self.priceLabel.attributedText = mutableString;
    
    NSString *string = [model.tab_list componentsJoinedByString:@"  "];
    [self.tab_listLabel setText:string];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
